// 2025/07/26
// Author: Forever
#include <bits/stdc++.h>
using namespace std;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec)
{
    os << "["; 
    bool first = true;
    for (const auto& item : vec) {
        if (!first)
            os << ", "; 
        os << item;
        first = false;
    }
    os << "]"; 
    return os;
}
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename A, typename B>
ostream& operator<<(ostream& os, const map<A, B>& m)
{
    os << "{";
    bool first = true;
    for (const auto& p : m) {
        if (!first)
            os << ", ";
        os << p.first << ": " << p.second;
        first = false;
    }
    os << "}";
    return os;
}
template <typename A, typename B>
ostream& operator<<(ostream& os, const unordered_map<A, B>& m)
{
    os << "{";
    bool first = true;
    for (const auto& p : m) {
        if (!first)
            os << ", ";
        os << p.first << ": " << p.second;
        first = false;
    }
    os << "}";
    return os;
}
#define error(args...)                           \
    {                                            \
        string _s = #args;                       \
        replace(_s.begin(), _s.end(), ',', ' '); \
        stringstream _ss(_s);                    \
        istream_iterator<string> _it(_ss);       \
        cout << "-----DEBUG-----" << endl;     \
        err(_it, args);                          \
        cout << "------END------" << endl;     \
    }
void err(istream_iterator<string> it) { }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cout << *it << " = " << a << endl;
        err(++it, args...);
}
void setIO(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (!name.empty()) {
        freopen((name + ".in").c_str(), "r", stdin);
        freopen((name + ".out").c_str(), "w", stdout);
    }
}
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int MOD;
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;

int t, cnt, m, mx[800005];

void add(int x, int pos, int l, int r, int p){
    if (l == r){
        mx[p] = x;
        return;
    }
    int m = l + ((r - l) >> 1);
    if (pos <= m)
        add(x, pos, l, m, p << 1);
    else
        add(x, pos, m + 1, r, (p << 1) | 1);
    mx[p] = max(mx[p << 1], mx[(p << 1) | 1]);
}

int query(int l, int r, int s, int t, int p){
    if (l <= s && t <= r)
        return mx[p];
    int m = s + ((t - s) >> 1);
    int res = 0;
    if (l <= m)
        res = max(res, query(l, r, s, m, p << 1));
    if (r > m)
        res = max(res, query(l, r, m + 1, t, (p << 1) | 1));
    return res;
}

signed main()
{
    memset(mx, -0x3f, sizeof(mx));
    setIO();
    cin >> m >> MOD;
    for (int i = 0; i < m; ++i){
        char c;
        int p;
        cin >> c >> p;
        if (c == 'A'){
            add((p + t) % MOD, ++cnt, 1, m, 1);
        }
        else{
            t = query(cnt - p + 1, cnt, 1, m, 1);
            cout << t << endl;
        }
    }
    return 0;
}